package com.EM1.www.servlet;

import com.EM1.www.dao.ConnectGrade;
import com.EM1.www.po.Student;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.ArrayList;

@WebServlet("/GradeMsg")
public class GradeMsg extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        String grade = request.getParameter("grade");
        if(grade.equals("请选择班级")){
//            request.setAttribute("warn","请选择要查询的班级");
            request.getRequestDispatcher("tip.jsp").forward(request,response);
        }else {
            int grade1=Integer.parseInt(grade);
            ConnectGrade connectGrade=new ConnectGrade();
            try {
                ArrayList<Student> students = connectGrade.selcetGrade(grade1);
                request.setAttribute("students",students);
                request.setAttribute("grade",grade1);
                request.getRequestDispatcher("grademsg.jsp").forward(request,response);
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }
}
